using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace Data.Models.Mapping
{
    public class MaterialFormulaMap : EntityTypeConfiguration<MaterialFormula>
    {
        public MaterialFormulaMap()
        {
            // Primary Key
            this.HasKey(t => t.ID);

            // Properties
            this.Property(t => t.Code)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.Name)
                .IsRequired()
                .HasMaxLength(150);

            // Table & Column Mappings
            this.ToTable("MaterialFormula");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.Code).HasColumnName("Code");
            this.Property(t => t.Name).HasColumnName("Name");
            this.Property(t => t.DesignDetailID).HasColumnName("DesignDetailID");
            this.Property(t => t.MaterialTypeID).HasColumnName("MaterialTypeID");
            this.Property(t => t.UOMID).HasColumnName("UOMID");
            this.Property(t => t.Quantity).HasColumnName("Quantity");
            this.Property(t => t.ProductModelID).HasColumnName("ProductModelID");

            // Relationships
            this.HasRequired(t => t.ProductModel)
                .WithMany(t => t.MaterialFormulas)
                .HasForeignKey(d => d.ProductModelID);

        }
    }
}
